package com.cloud.school.bus.teacherhelper.protocol.classmanage;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONObject;

import com.cloud.school.bus.teacherhelper.entitys.Student;
import com.cloud.school.bus.teacherhelper.protocol.baseresponse.BaseJsonHttpResponse;

public class SearchStudentResponse extends BaseJsonHttpResponse {

	protected List<Student> studentList = new ArrayList<Student>();
	protected int result = 0;

	@Override
	public void onSuccess(int statusCode, Header[] headers,
			String responseString) throws Throwable {
		if ("1".equals(code)) {
			JSONObject mainJsonObject = new JSONObject(responseString);
			result = mainJsonObject.optInt("result", 0);
			JSONArray studentJsonArray = mainJsonObject.optJSONArray("student");
			if (null != studentJsonArray) {
				for (int i = 0; i < studentJsonArray.length(); i++) {
					JSONObject itemJsonObject = studentJsonArray
							.optJSONObject(i);
					if (null != itemJsonObject) {
						Student student = new Student();
						student.uid_class = itemJsonObject.optString("uid_class", "");
						student.classid = itemJsonObject.optString("classid", "");
						student.studentid = itemJsonObject.optString("studentid", "");
						student.student_uid = itemJsonObject.optString("student_uid", "");
						student.cnname = itemJsonObject.optString("cnname", "");
						student.mobile = itemJsonObject.optString("mobile", "");
						student.birthday = itemJsonObject.optString("birthday", "");
						student.sex = itemJsonObject.optString("sex", "");
						student.classname = itemJsonObject.optString("classname", "");
						studentList.add(student);
					}
				}
			}
		}
	}

}
